package com.sto.stoapp.activity.administrator.system;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.db.StoFilePreference;
import com.sto.stoapp.widget.StoHomeActivity;
import com.sto.stoapp.widget.StoSelectLinearLayout;

public class SystemKeyMgrActivity extends StoHomeActivity {
	StoSelectLinearLayout soundSwitch, lightSwitch;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.key_mgr_layout);
		Bundle extras = getIntent().getExtras();
		this.setTitleBottom(R.string.touch_screen_set,
				extras.getString("busiType"));
		initView();
	}

	private void initView() {
		soundSwitch = (StoSelectLinearLayout) findViewById(R.id.sound_switch);
		soundSwitch.setTitle("按键声音");
		soundSwitch.setSelectStatus(StoFilePreference.getInstance(this)
				.getPromptSound());
		lightSwitch = (StoSelectLinearLayout) findViewById(R.id.light_switch);
		lightSwitch.setTitle("按键背光");
		lightSwitch.setSelectStatus(StoFilePreference.getInstance(this)
				.getLightSwitch());
		soundSwitch.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				soundSwitch.setSelectStatus(!soundSwitch.getSelectStatus());
				StoFilePreference.getInstance(SystemKeyMgrActivity.this)
						.setPromptSound(soundSwitch.getSelectStatus());
				sound(SystemKeyMgrActivity.this, soundSwitch.getSelectStatus());

			}
		});

		lightSwitch.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				lightSwitch.setSelectStatus(!lightSwitch.getSelectStatus());
				StoFilePreference.getInstance(SystemKeyMgrActivity.this)
						.setLightSwitch(lightSwitch.getSelectStatus());
				light(SystemKeyMgrActivity.this, lightSwitch.getSelectStatus());

			}
		});

	}

	public static void sound(Context c, boolean status) {
		Intent intent = new Intent("com.kaicom.keydown.sound");
		intent.putExtra("com.kaicom.keydown.sound", status);
		System.out.println("com.kaicom.keydown.sound:"+status);
		c.sendBroadcast(intent);
	}

	public static void light(Context c, boolean status) {
		Intent intent = new Intent("com.kaicom.keypad.lights");
		System.out.println("com.kaicom.keypad.lights:"+status);
		intent.putExtra("com.kaicom.keypad.lights", status);
		c.sendBroadcast(intent);
	}

}
